package com.learn.str;

import java.lang.reflect.Field;

/**
 * @version 1.0
 * @author: CRM_SYSTEM
 * @date: 2023/2/16 22:15
 * @Description:
 */
public class StringTest {
    public static void main(String[] args) throws Exception {
//        String a="abc";
//        System.out.println(a);
//        System.out.println(a.hashCode());
//        String update = StringUpdate(a);
//        System.out.println(update);
//        System.out.println(update.hashCode());
//
//        String add = StringAdd(a);
//        System.out.println(add);
//        System.out.println(add.hashCode());

        ThreadTest();

    }


    public static String StringUpdate(String a) throws Exception {
        Field field = String.class.getDeclaredField("value");
        field.setAccessible(true);
        char[] chars = (char[]) field.get(a);
        chars[1]='B';
        return a;
    }

    public static String StringAdd(String a) throws Exception {
        Field field = String.class.getDeclaredField("value");
        field.setAccessible(true);
        field.set(a,new char[]{'a','b','c','d','e'});
        return a;
    }

    static void ThreadTest(){
        Thread t=new Thread(()->{
            try {
                Thread.sleep(4000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("开始！");
        });
        t.start();
//        t.start();
        t.interrupt();
    }
}
